<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong> 无效的招标信息！
</div>
<#else>
<form class="bid-result-form" action="${request.contextPath}/bid/add-result" method="post" enctype="multipart/form-data">
	<input type="hidden" name="result.bid.id" value="${bidId}" /> <input type="hidden" name="result.status" value="${status}" />
	<div class="row">
		<!-- 未中标（包含：未中标、流标） -->
		<#if "B0004_LOSE"==status>
		<div class="col-md-12 win-company">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">中标单位</div>
					</div>
					<input type="text" class="form-control" name="result.winCompany" placeholder="最多60个汉字">
				</div>
			</div>
		</div>
		</#if>
		<!-- 中标、未中标 -->
		<#if ["B0003_WIN", "B0004_LOSE"]?seq_contains(status) && !('KJ_BID'==qt)>
		<div class="col-md-12 final-money">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> <#if 'SINGLE'==qt> ${qt.value} <#elseif 'TOTAL'==qt> ${qt.value} <#elseif 'DROP_POINT'==qt> ${qt.value}（%） </#if>
						</div>
					</div>
					<#if 'TOTAL'==qt> <input type="text" class="form-control not-empty number" name="result.finalMoney" placeholder="请输入数字">
					<div class="input-group-addon">元</div>
					<#elseif 'SINGLE'==qt>
					<textarea row="3" class="form-control not-empty" name="result.finalMoneyDesc" placeholder="请填写中标单价说明"></textarea>
					<#elseif 'DROP_POINT'==qt>
					<textarea row="3" class="form-control not-empty" name="result.finalMoneyDesc" placeholder="请填写中标降点说明"></textarea>
					</#if>
				</div>
			</div>
		</div>
		</#if>
		<!-- 中标 -->
		<#if "B0003_WIN"==status>
		<div class="col-md-12">
			<div class="form-group">
				<label class="form-control"> <input type="checkbox" id="need-bid-server-money" checked="checked"> <span>已算出中标服务费</span>
				</label>
			</div>
		</div>
		<div class="col-md-6 server-money">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 中标服务费
						</div>
					</div>
					<input type="hidden" name="money[0].bid.id" value="${bidId}"> <input type="hidden" name="money[0].payOut" value="true"> <input type="hidden" name="money[0].inAccount" value="true"> <input type="hidden" name="money[0].name" value="中标服务费"> <input type="hidden" name="money[0].invoice" value="true"> <input type="text" class="form-control not-empty number" name="money[0].total" placeholder="填写金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-6 server-money">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 缴纳时间
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" name="money[0].time" data-foot="false" data-format="yyyy-MM-dd" value="${.now?string('yyyy-MM-dd')}" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12 final-money">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 中标通知书
						</div>
					</div>
					<input type="file" name="bidNoticeFile" class="hidden"> <input type="text" class="form-control not-empty file-show" placeholder="请选择相关文件。" readonly="readonly">
				</div>
			</div>
		</div>
		</#if>
		<!-- 流标重投  -->
		<#if "B0002_MISS_REBID"==status>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 开标时间
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" data-format="yyyy-MM-dd HH:mm" name="reOpenTime" placeholder="请选择日期时间" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 投标保证金
						</div>
					</div>
					<input type="hidden" name="money[0].bid.id" value="${bidId}"> <input type="hidden" name="money[0].id" value="${data.tbbzj.id}"> <input type="hidden" name="money[0].payOut" value="${((data.tbbzj.payOut)?string('true','false'))!''}"> <input type="hidden" name="money[0].gaveBack" value="${((data.tbbzj.gaveBack)?string('true','false'))!''}"> <input type="hidden" name="money[0].inAccount" value="${((data.tbbzj.inAccount)?string('true','false'))!''}"> <input type="hidden" name="money[0].name" value="${data.tbbzj.name}"> <input type="hidden" name="money[0].source" value="${data.tbbzj.source}"> <input type="hidden" name="money[0].invoice"
						value="${((data.tbbzj.invoice)?string('true','false'))!''}"> <input type="text" class="form-control not-empty number" name="money[0].total" value="${data.tbbzj.total}" placeholder="填写金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 支出日期
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" name="money[0].time" value="${(data.tbbzj.time?string('yyyy-MM-dd'))!''}" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 回收日期
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" name="money[0].backTime" value="${(data.tbbzj.backTime?string('yyyy-MM-dd'))!''}" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		</#if>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">备注</div>
					</div>
					<textarea rows="5" class="form-control" name="result.remark"></textarea>
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="Suredy.Modal.closeModal();">关闭</div>
		</div>
	</div>
</form>
<hr>
<script type="text/javascript">
	require([ '${request.contextPath}/app/js/form-checker.js', 'suredyModal', '${request.contextPath}/app/js/file.js', 'suredyDatetimepicker', 'jqueryForm' ], function(formChecker, Modal) {
		// 未中标与流标进行切换
		$('input[name="x"]').on('click', function() {
			$('form.bid-result-form').get(0).reset();

			var $this = $(this);
			var thisId = $this.attr('id');

			$this.prop('checked', true);

			var status = $('input[name="result.status"]');
			var winCompany = $('.win-company');
			var finalMoney = $('.final-money');

			if ('miss' == thisId) {
				status.val('B0005_MISS');

				winCompany.fadeOut(100);
				finalMoney.fadeOut(100);

				$('input[name=winCompany]', winCompany).val('');
				$('input[name=finalMoney]', finalMoney).val('');
				$('input[name="result.finalMoney"]').removeClass('not-empty').removeClass('number');
			} else if ('lose' == thisId) {
				status.val('B0004_LOSE');
				winCompany.fadeIn(100);
				finalMoney.fadeIn(100);
				$('input[name="result.finalMoney"]').addClass('not-empty').addClass('number');
			}
		});

		$('form.bid-result-form .btn-submit').on('click', function() {
			var form = $('form.bid-result-form');

			// 校验表单
			if (!formChecker(form)) {
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						var msg = (data && data.msg) || '记录招标结果失败!';
						alert(msg);
						$this.removeClass('disabled');
						return false;
					}

					Suredy.refreshContent('${bidId}', [ 'div.suredy-tabs' ]);

					Modal.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('记录招标结果失败!\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
